package utils;

import ga.BotoxGA;
import ga.Error;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import tablaSimbolos.TS;

public class RefsAChequear {

	private List<InfoRef> refsAChequear;

	public RefsAChequear() {
		refsAChequear = new LinkedList<InfoRef>();
	}

	public RefsAChequear(LinkedList<InfoRef> refsAChequear) {
		this.refsAChequear = refsAChequear;
	}

	public List<InfoRef> getRefsAChequear() {
		return refsAChequear;
	}

	public void setRefsAChequear(List<InfoRef> refsAChequear) {
		this.refsAChequear = refsAChequear;
	}

	public Error tiposNoDeclarados(TS ts) {
		boolean err = true;
		for (Iterator<InfoRef> it = refsAChequear.iterator(); err && it.hasNext(); ) {
			Info t = it.next();
			if (t instanceof InfoRef && !ts.existeID(((InfoRef) t).getId())) {
				err = false;
			}
		}
		return BotoxGA.errorSi(!err, "El tipo base declarado no existe.");
	}

	public void aniadeRef(InfoRef ref) {
		refsAChequear.add(ref);
	}

	public RefsAChequear unir(RefsAChequear val) {
		refsAChequear.addAll(val.getRefsAChequear());
		return this;
	}

	public String toString() {
		return refsAChequear.toString();
	}
}
